package com.mx.jdbc.ymate.config;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

import static com.mx.jdbc.ymate.contants.JdbcContants.DEFAULT_DS;

/**
 * @Author: 徐建鹏.
 * @create: 2021-09-15 14:17
 * @Description:
 */
@Configuration
@Validated
@ConfigurationProperties(prefix = "mx.jdbc.ymate")
public class JdbcProperties {


    //默认数据源名称, 默认值: default
    private String dsDefaultName;

    //数据源列表, 多个数据源名称间用'|'分隔, 默认值: default
    private String dsNamelist;

    @NotNull
    @Valid
    private List<DataSourceConfig> datasources = new ArrayList<>();

    //是否使用类名后缀, 不使用和使用的区别如: User->UserModel, 默认值: false
    private Boolean useBaseEntity = false;

    //是否使用类名后缀, 不使用和使用的区别如: User->UserModel, 默认值: false
    private Boolean useClassSuffix = false;

    //实体类名后缀, 默认值: model
    private String classSuffix;

    //是否采用链式调用模式, 默认值: false
    private Boolean useChainMode = false;

    // 自定义表或字段名称过滤器, 默认值: 空
    private String namedFilterClass;

    //数据库名称
    @NotNull
    private String dbName;

    //数据库用户名称
    @NotNull
    private String dbUsername;

    //数据库表名称前缀, 多个用'|'分隔, 默认值: 空
    private String tablePrefix;

    //否剔除生成的实体映射表名前缀, 默认值: false
    private Boolean removeTablePrefix = false;

    //预生成实体的数据表名称列表, 多个用'|'分隔, 默认值: 空(即全部生成)
    private String tableList;

    //排除的数据表名称列表, 在此列表内的数据表将不被生成实体, 多个用'|'分隔, 默认值: 空
    private String tableExcludeList;

    //需要添加@Readonly注解声明的字段名称列表, 多个用'|'分隔, 默认值: 空
    private String readonlyFieldList;

    //生成的代码文件输出路径, 默认值: ${root}/src/main/java
    private String outputPath;

    //生成的代码所属包名称, 默认值: packages
    private String packageName;

    //repository xml文件位置 默认repository/
    private String repositoryXmlPath;

    public List<DataSourceConfig> getDatasources() {
        return datasources;
    }

    public void setDatasources(List<DataSourceConfig> datasources) {
        this.datasources = datasources;
    }

    public String getDsDefaultName() {
        return dsDefaultName;
    }

    public void setDsDefaultName(String dsDefaultName) {
        this.dsDefaultName = StringUtils.defaultIfBlank(dsDefaultName, DEFAULT_DS);
    }

    public String getDsNamelist() {
        return dsNamelist;
    }

    public void setDsNamelist(String dsNamelist) {
        this.dsNamelist = StringUtils.defaultIfBlank(dsNamelist, DEFAULT_DS);
    }

    public Boolean isUseBaseEntity() {
        return useBaseEntity;
    }

    public void setUseBaseEntity(Boolean useBaseEntity) {
        this.useBaseEntity = useBaseEntity;
    }

    public Boolean isUseClassSuffix() {
        return useClassSuffix;
    }

    public void setUseClassSuffix(Boolean useClassSuffix) {
        this.useClassSuffix = useClassSuffix;
    }

    public String getClassSuffix() {
        return classSuffix;
    }

    public void setClassSuffix(String classSuffix) {
        this.classSuffix = classSuffix;
    }

    public Boolean isUseChainMode() {
        return useChainMode;
    }

    public void setUseChainMode(Boolean useChainMode) {
        this.useChainMode = useChainMode;
    }

    public String getNamedFilterClass() {
        return namedFilterClass;
    }

    public void setNamedFilterClass(String namedFilterClass) {
        this.namedFilterClass = namedFilterClass;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public String getDbUsername() {
        return dbUsername;
    }

    public void setDbUsername(String dbUsername) {
        this.dbUsername = dbUsername;
    }

    public String getTablePrefix() {
        return tablePrefix;
    }

    public void setTablePrefix(String tablePrefix) {
        this.tablePrefix = tablePrefix;
    }

    public Boolean isRemoveTablePrefix() {
        return removeTablePrefix;
    }

    public void setRemoveTablePrefix(Boolean removeTablePrefix) {
        this.removeTablePrefix = removeTablePrefix;
    }

    public String getTableList() {
        return tableList;
    }

    public void setTableList(String tableList) {
        this.tableList = tableList;
    }

    public String getTableExcludeList() {
        return tableExcludeList;
    }

    public void setTableExcludeList(String tableExcludeList) {
        this.tableExcludeList = tableExcludeList;
    }

    public String getReadonlyFieldList() {
        return readonlyFieldList;
    }

    public void setReadonlyFieldList(String readonlyFieldList) {
        this.readonlyFieldList = readonlyFieldList;
    }

    public String getOutputPath() {
        return outputPath;
    }

    public void setOutputPath(String outputPath) {
        this.outputPath = outputPath;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getRepositoryXmlPath() {
        return repositoryXmlPath;
    }

    public void setRepositoryXmlPath(String repositoryXmlPath) {
        this.repositoryXmlPath = StringUtils.defaultIfBlank(repositoryXmlPath, "/repository/");
    }
}
